<?php
/*
 * Author: Quan Van Sinh
 * Email: sinhvnb@vietnambiz.com
 */
checkLoginHeader();
checkPermission();
$comment = new comment();
$comment->commentAction();
?>
<?php include_once $config ['admin_theme_path'] . $config ['admin_theme'] . '/header.php'; ?>


<script type="text/javascript">

    function deleteComment(id,txtAlert){
        if (confirm("Do you want to delete "+txtAlert+"?")){
            $.ajax({
                url: '/<?php echo $config ['admin_section']; ?>/comment',
                type: 'POST',
                data: "id="+id+"&commentActionType=deleteComment",
                error: function(){
                    alert('Error loading comment infomation');
                },
                success: function(){
                    window.location.reload(true);
                }
            });
        }
    }

    function toggle(id,obj,detail){
        if(id!=''){
            $.ajax({
                url: '/<?php echo $config ['admin_section']; ?>/comment',
                type: 'POST',
                data: "id="+id+"&commentActionType=updateStatus",
                error: function(){
                    alert('Error loading article infomation');
                },
                success: function(data){
                    
                    if(data=='yes'){
                        if(detail==1){
                            $('#comment'+id).attr('src', '<? echo $config ['admin_images_url']; ?>/icons/circle-green.png');
                            $('#comment'+id).attr('title', 'Comment is actived!');
                        }
                        obj.src = '<? echo $config ['admin_images_url']; ?>/icons/circle-green.png';
                        obj.title = 'Comment is actived!';
                        
                    }else if(data=='no'){
                        if(detail==1){
                            $('#comment'+id).attr('src', '<? echo $config ['admin_images_url']; ?>/icons/circle-red.png');
                            $('#comment'+id).attr('title', 'Comment is not actived!');
                        }
                        obj.src = '<? echo $config ['admin_images_url']; ?>/icons/circle-red.png';
                        obj.title = 'Comment is not actived!';
                    }else{
                        window.location.reload(true);
                    }
                }
            });
        }
    }

    $(document).ready(function(){
        setTimeout("closeResultMessages()",5000);
    });
    function closeResultMessages(){
        document.getElementById('rsMessages').style.display = 'none';
    }
    

</script>

<div id="wrapper">
    <div id="content" style="width: 98%;">


        <div id="rightnow">
            <h3 class="reallynow">
                <span>Comments</span>
                <span style="float: right;"><a href="/<?php echo $config ['admin_section']; ?>/comment">Go back</a></span>
                <br />
            </h3>
            <div class="youhave">
                <div id="rsMessages" style="text-align: center; color: red; font-weight: bolder"><? if (isset($_SESSION['rsMessages'])) {
    echo $_SESSION['rsMessages'];
    $_SESSION['rsMessages'] = '';
} ?></div>
                <table width="100%">

                    <tbody>
                        <tr>
                            <td width="40px">&nbsp;</td>
                            
                            <td><b>Comment</b></td>

                            <td width="60px"><b>Action</b></td>
                        </tr>
                        <?php
                        $comment = $comment->getAllCommentByArticle($_GET['id']);
                        $i = 0;
                        while ($rs = $db->fetch_array($comment)) {
                            $i++;
                            if ($rs['status'] == 'yes') {
                                $frontPageImg = 'circle-green.png';
                                $frontPageTitle = 'Comment is actived!';
                            } else {
                                $frontPageImg = 'circle-red.png';
                                $frontPageTitle = 'Comment is not actived!';
                            }
                        ?>

                            <tr class="comment">
                                <td class="a-center"><?php echo $i; ?></td>
                                <td>
                                    <div>
                                        <b><?php echo $rs['name']; ?></b> <span style="color: #929292">(<?php echo $rs['email']; ?>)</span><span style="float:right;color: #929292"> <?php echo $rs['create_date']; ?></span>
                                        <br><br>
                                        <div style="margin: 0 0 10px 10px;"><?php echo stripcslashes($rs['comment']); ?></div>
                                    </div>
                                </td>
                                <td>
                                    <a href="/<?php echo $config ['admin_section']; ?>/detail?id=<?php echo $rs['aid'];?>&keepThis=true&TB_iframe=true&height=550&width=500" class="thickbox"><img height="16" width="16" title="View article" src="<? echo $config ['admin_images_url']; ?>/icons/page_white_text_width.png"/></a>
                                    <img id="comment<?php echo $rs['id']; ?>" onclick="javascript: toggle('<?php echo $rs['id']; ?>',this,0);" height="16" width="16" title="<?php echo $frontPageTitle; ?>" src="<? echo $config ['admin_images_url']; ?>/icons/<?php echo $frontPageImg; ?>" style="cursor:pointer"/>
                                    <a href="javascript: deleteComment('<?php echo $rs['id']; ?>','<?php echo $rs['name']; ?>');"><img height="16" width="16" title="Delete this comment" src="<? echo $config ['admin_images_url']; ?>/icons/page_white_delete.png"/></a>
                                </td>
                            </tr>

                        <?php
                        }
                        ?>


                    </tbody>
                </table>
            </div>
        </div>
    </div>


</div>
<?php include_once $config ['admin_theme_path'] . $config ['admin_theme'] . '/footer.php'; ?>